package com.own.component.util.excel.util.write.style.item;

import com.own.component.util.excel.util.write.style.base.AbstractStyleFunction;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.xssf.usermodel.XSSFColor;

/**
 * StyleItemBorderColor
 *
 * @author chenxueli
 * @date 2023-05-11 16:10:00
 */
public class StyleItemBorderColor extends AbstractStyleFunction<XSSFColor> {

    private final XSSFColor top;
    private final XSSFColor bottom;
    private final XSSFColor left;
    private final XSSFColor right;

    public StyleItemBorderColor(XSSFColor item) {
        this(item, item, item, item);
    }

    public StyleItemBorderColor(XSSFColor topBottom, XSSFColor rightLeft) {
        this(topBottom, rightLeft, topBottom, rightLeft);
    }

    public StyleItemBorderColor(XSSFColor top, XSSFColor right, XSSFColor bottom, XSSFColor left) {
        super(null);
        this.top = top;
        this.right = right;
        this.bottom = bottom;
        this.left = left;
    }

    /**
     * 使用样式
     *
     * @param style 样式
     */
    @Override
    public void apply(CellStyle style) {
        if (top != null) {
            style.setTopBorderColor(top.getIndex());
        }
        if (bottom != null) {
            style.setBottomBorderColor(bottom.getIndex());
        }
        if (left != null) {
            style.setLeftBorderColor(left.getIndex());
        }
        if (right != null) {
            style.setRightBorderColor(right.getIndex());
        }
    }

}
